package com.haohan.jingyuan.customer.helper;

import cn.hutool.json.JSONUtil;
import com.haohan.jingyuan.customer.dto.resp.FileAuthInfoResp;
import com.haohan.jingyuan.customer.entity.CustomerFileAuth;

import java.util.List;

/**
 * 文件授权响应对象转换工具类
 * 
 * @ClassName FileAuthRespHelper
 * @Description 文件授权响应对象转换工具
 * @Author hexijun
 * @Time 2025/11/05 14:00
 * @Version 1.0
 */
public class FileAuthRespHelper {

    /**
     * 将文件授权实体转换为文件授权信息响应对象
     * 
     * @param customerFileAuth 文件授权实体
     * @return 文件授权信息响应对象
     */
    public static FileAuthInfoResp convert2FileAuthInfoResp(CustomerFileAuth customerFileAuth) {
        if (customerFileAuth == null) {
            return null;
        }

        FileAuthInfoResp fileAuthInfoResp = new FileAuthInfoResp();
        fileAuthInfoResp.setId(customerFileAuth.getId());
        fileAuthInfoResp.setCustomerId(customerFileAuth.getCustomerId());
        fileAuthInfoResp.setAuthType(customerFileAuth.getAuthType());
        
        // 将fileIds从JSON字符串转换为List
        if (customerFileAuth.getFileIds() != null && !customerFileAuth.getFileIds().trim().isEmpty()) {
            List<String> fileIds = JSONUtil.toList(customerFileAuth.getFileIds(), String.class);
            fileAuthInfoResp.setFileIds(fileIds);
        }
        
        fileAuthInfoResp.setUserName(customerFileAuth.getUserName());
        fileAuthInfoResp.setPassword(customerFileAuth.getPassWord());
        fileAuthInfoResp.setUkid(customerFileAuth.getUkid());
        fileAuthInfoResp.setCreator(customerFileAuth.getCreator());
        fileAuthInfoResp.setGmtCreated(customerFileAuth.getGmtCreated());
        fileAuthInfoResp.setModifier(customerFileAuth.getModifier());
        fileAuthInfoResp.setGmtModified(customerFileAuth.getGmtModified());
        fileAuthInfoResp.setIsDeleted(customerFileAuth.getIsDeleted());

        return fileAuthInfoResp;
    }
}

